package com.jiajia.study.stack;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zjiajia
 * @date 2023/11/12 22:37
 */
public class Demo6 {
    public static void main(String[] args) throws JsonProcessingException {

        Dept dept = new Dept("市场部");

        Emp emp = new Emp("张三");
        emp.setDept(dept);
        Emp emp1 = new Emp("李四");
        emp1.setDept(dept);

        List<Emp> empList = new ArrayList<>();
        empList.add(emp);
        empList.add(emp1);

        dept.setEmpList(empList);

        ObjectMapper objectMapper = new ObjectMapper();

        System.out.println(objectMapper.writeValueAsString(dept));


    }
}

class Emp{
    /**
     * 员工名称
     */
    private String name;
    /**
     * 员工所属部门
     */
    @JsonIgnore
    private Dept dept;

    public Emp(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }
}

class Dept{
    /**
     * 部门名称
     */
    private String name;
    /**
     * 部门员工
     */
    private List<Emp> empList;

    public Dept(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Emp> getEmpList() {
        return empList;
    }

    public void setEmpList(List<Emp> empList) {
        this.empList = empList;
    }
}
